﻿using MediatR;
using Yuekao.API.Read.Command;
using Yuekao.Domain.API;
using Yuekao.Domain.BaseReposi;
using Yuekao.Domain.Entitys;

namespace Yuekao.API.Read.CommandHandler
{
    public class GetWorkHandler : IRequestHandler<GetWorkCommand, APIPagging<Work>>
    {
        private readonly IBaseRepository<Work> workRepo;

        public GetWorkHandler(IBaseRepository<Work> workRepo)
        {
            this.workRepo = workRepo;
        }
        /// <summary>
        /// 职称列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<APIPagging<Work>> Handle(GetWorkCommand request, CancellationToken cancellationToken)
        {
            APIPagging<Work> res=new APIPagging<Work>();
            var work = workRepo.GetAll();
            res.Code = APIEnum.Success;
            res.PageData = work.ToList();
            res.Data = res.PageData.FirstOrDefault(); // 设置Data属性为第一个元素或默认值
            return res;
        }
    }
           
        
}
